package com.coder.gaeblogger.listener;


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.coder.gaeblogger.comm.Enums;
import com.coder.gaeblogger.domain.User;
import com.coder.gaeblogger.manager.UserManager;

public class ApplicationListener implements ServletContextListener {

	private static final String userName = "admin";

	public void contextInitialized(ServletContextEvent se) {
		UserManager userM = new UserManager();		
		User user = null;
		try{
			user = (User) userM.getByField(User.class, "userName", userName);
		}catch(Exception ex){}		
		if(user == null){
			user = new User();
			user.setPassword("admin");
			user.setUserName(userName);
			user.setFullName("Admin User");
			user.setEmail("admin@domain.com");
			user.setStatus(Enums.Status.Active.getId());
			
			userM.saveUser(user);
		}
		

	}

	public void contextDestroyed(ServletContextEvent se) {
	}
}
